/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.dto.TaskPlanPageQueryDTO;
import org.springblade.modules.admin.entity.MaintainTemplateContent;
import org.springblade.modules.admin.entity.MaintainTemplateContentScoreDimension;
import org.springblade.modules.admin.enums.TemplateContentStandardEnum;
import org.springblade.modules.admin.service.MaintainTemplateContentService;
import org.springblade.modules.admin.service.MaintainTemplateLocationTypeService;
import org.springblade.modules.admin.vo.TaskStatusVO;
import org.springblade.modules.admin.vo.TemplateContentDetailVO;
import org.springblade.modules.admin.vo.TemplateContentPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date 10:57 2022/3/14
 * @Description {
 *    工作项相关接口
 * }
 * @Author lsay
 **/
@RestController
@RequestMapping("/maintain/template/content")
public class MaintainTemplateContentController {

	@Autowired
	private MaintainTemplateContentService templateContentService;

	/**
	 * 工作项分页查询
	 * @param pageQueryDTO
	 * @param query
	 * @return
	 */
	@TenantIgnore
	@GetMapping("/page")
	public R<IPage<TemplateContentPageVO>> selectTemplateContentPage(TaskPlanPageQueryDTO pageQueryDTO, Query query){
		return R.data(templateContentService.selectTemplateContentPage(pageQueryDTO, Condition.getPage(query)));
	}

	/**
	 * 获取工作项详情
	 * @param id 主键id
	 * @return 详情
	 */
	@TenantIgnore
	@GetMapping("/detail")
	public R<TemplateContentDetailVO> selectTemplateContentDetail(Long id){
		return R.data(templateContentService.selectTemplateContentDetail(id));
	}

	/**
	 * 新增工作项
	 * @param templateContent 入参信息
	 * @return 是否成功
	 */
	@PostMapping("/save")
	public R<Boolean> saveTemplateContent(@RequestBody MaintainTemplateContent templateContent){
		return R.status(templateContentService.saveTemplateContent(templateContent));
	}

	/**
	 * 修改工作项
	 * @param id 工作项id
	 * @param templateContent 入参信息
	 * @return 是否成功
	 */
	@TenantIgnore
	@PutMapping("/{id}")
	public R<Boolean> updateTemplateContent(@PathVariable Long id,@RequestBody MaintainTemplateContent templateContent){
		return R.status(templateContentService.updateTemplateContent(id,templateContent));
	}

	/**
	 * 工作项复制
	 * @param templateContent
	 * @return
	 */
	@TenantIgnore
	@PostMapping("/copy")
	public R<Boolean> copy(@RequestBody MaintainTemplateContent templateContent){
		return R.status(templateContentService.copy(templateContent.getId()));
	}

	/**
	 * 删除工作项
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/remove")
	public R<Boolean> removeTemplateContent(String ids){
		return R.status(templateContentService.removeTemplateContent(Func.toLongList(ids)));
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   获取模板工作项标准
	 * }
	 * @Date 11:26 2023/5/26
	 * @Param
	 * @return
	 **/
	@GetMapping("/standard")
	public R<List<TaskStatusVO>> getStandard(){
		return R.data(TemplateContentStandardEnum.getStandard());
	}

	/**
	 * 工作项复制 批量
	 * @param contentList
	 * @return
	 */
	@TenantIgnore
	@PostMapping("/copy/bach")
	public R<Boolean> copyBach(@RequestBody List<MaintainTemplateContent> contentList){
		return R.status(templateContentService.copyBach(contentList));
	}

	/**
	 * 批量更新工作项评分设置
	 * @param
	 * @return
	 */
	@TenantIgnore
	@PostMapping("/update/bach/score/{partScore}")
	public R<Boolean> updateBachScore(@PathVariable Integer partScore,@RequestBody List<Long> contentIds){
		return R.status(templateContentService.updateBachScore(partScore,contentIds));
	}
}
